package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.SetmealDto;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {


    @Autowired
    private SetmealService setmealService;

    @PostMapping
    public R add(@RequestBody SetmealDto setmealDto){
        R r = setmealService.add(setmealDto);
        return r;
    }
    //分页查询
    @GetMapping("/page")
    public R findPage(Integer page,Integer pageSize,String name){
        return setmealService.findPage(page,pageSize,name);
    }
    //批量删除套餐
    @DeleteMapping
    public R removeIds(Long[] ids){
        setmealService.removeIds(ids);
        return R.success("批量删除成功");
    }
    //批量起售停售
    @PostMapping("/status/{status}")
    public R modyfiStatus(Long[] ids,@PathVariable Integer status){
        return setmealService.modyfiStatus(ids,status);
    }
    //套餐回显
    @GetMapping("/{id}")
    public R findById(@PathVariable Long id){
        return setmealService.findById(id);
    }
    //修改保存功能
    @PutMapping()
    public R modyfi(@RequestBody SetmealDto setmealDto){
        R r = setmealService.modyfi(setmealDto);
        return r;
    }
    //根据分类id查询套餐列表
    @GetMapping("/list")
    public R list(Long categoryId,Integer status){
        R r = setmealService.list(categoryId,status);
        return r;
    }
}
